package com.lijianpo.util.extension.exceptions;

import com.lijianpo.util.extension.api.IErrorCode;

/**
 * 自定义扩展异常类
 * @author zhangyang
 * @Date 2021/4/21 14:55
 */
public abstract class AbstractExtensionException extends RuntimeException {

    protected IErrorCode errorCode;

    public AbstractExtensionException(IErrorCode errorCode) {
        super(errorCode.getMsg());
        this.errorCode = errorCode;
    }

    public AbstractExtensionException(String message){
        super(message);
        this.errorCode = new IErrorCode() {
            @Override
            public String getMsg() {
                return message;
            }
        };
    }

    public AbstractExtensionException(IErrorCode errorCode,String message) {
        super(message);
        this.errorCode = errorCode;
    }

    public AbstractExtensionException(Throwable cause){
        super(cause);
        this.errorCode = new IErrorCode() {
            @Override
            public String getMsg() {
                return cause.getMessage();
            }
        };
    }

    public AbstractExtensionException(String message, Throwable cause) {
        super(message, cause);
        this.errorCode = new IErrorCode() {
            @Override
            public String getMsg() {
                return message;
            }
        };
    }

    public IErrorCode getErrorCode() {
        return errorCode;
    }


}
